import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/custom_footer.dart';
import 'package:app/pages/cooperate_modules/cooperate_controller.dart';
import 'package:app/router/app_pages.dart';
import 'package:app/services/address.dart';
import 'package:app/utils/hexcolor.dart';
import 'package:bruno/bruno.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import '../../utils/search_module.dart';
import 'cooperate_detail_moodule/cooperate_detail_view.dart';
import 'cooperate_model.dart';

class CooperateView extends GetView{

  @override
  final CooperateController controller = Get.put(CooperateController());

  CooperateView({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: AppBar(
          title: Text('协作',style: TextStyle(color: AppColor.textColor),),
        ),
      ),
      body: GetBuilder<CooperateController>(builder: (_){
        return GestureDetector(
          onTap: () {
            /// 页面点击响应
            SearchModule.closeKeyboard(context);
          },
          onPanDown: (_) {
            /// 列表滑动响应
            SearchModule.closeKeyboard(context);
          },
          child: Column(
            children: [
              SizedBox(
                height: 55,
                child: BrnSearchText(
                  // focusNode: focusNode,
                  controller: controller.searchTextEditingController,
                  innerColor: HexColor('#F3F3F3'),
                  borderRadius: BorderRadius.all(Radius.circular(18)),
                  // searchController: scontroller..isActionShow = true,
                  onTextClear: () {
                    return false;
                  },
                  autoFocus: false,
                  onActionTap: () {
                    // scontroller.isClearShow = false;
                    // scontroller.isActionShow = false;
                    // focusNode.unfocus();
                    // BrnToast.show('取消', context);
                  },
                  onTextCommit: (text) {
                    // BrnToast.show('提交内容 : $text', context);
                  },
                  onTextChange: (text) {
                    // BrnToast.show('输入内容 : $text', context);
                    controller.requestData(search: text);
                  },
                ),
              ),

              Container(
                height: 100,
                color: Colors.white,
                padding: const EdgeInsets.only(left: 25,right: 25),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    GestureDetector(
                      onTap: (){
                        Get.toNamed(AppRoutes.approvalView);
                      },
                      child:   Column(
                        children: [
                          Image.asset('images/ic_xiezuo_shenpi.png',width: 70,height: 70,),
                          Text('审批')
                        ],
                      ),
                    ),
                    Column(
                      children: [
                        Image.asset('images/ic_xiezuo_daiban.png',width: 70,height: 70,),
                        Text('代办')
                      ],
                    ),
                    Column(
                      children: [
                        Image.asset('images/ic_xiezuo_tongzhi.png',width: 70,height: 70,),
                        Text('通知')
                      ],
                    ),
                  ],
                ),
              ),
              Expanded(child: EasyRefresh.custom(
                controller: controller.easyRefreshController,
                onRefresh:() =>controller.onRefresh(),
                onLoad:() => controller.onLoad(),
                footer: MaterialFooter1(),
                slivers: [
                  SliverPadding(padding: const EdgeInsets.only(top: 5),
                    sliver:SliverList(delegate: _mySliverChildBuilderDelegate()),)
                ],
              )),
            ],
          ),
        );
      }),
    );
  }
  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {
            CooperateItemModel model = controller.dataArr[index];
        return GestureDetector(
          onTap: ()async{
            Get.to(CooperateDetailPage(model.id));
          },
          child:  Column(
            children: [
              Container(
                // height: 100,
                padding: EdgeInsets.all(15),
                color: Colors.white,
                child:   Row(
                  children: [
                    Container(
                      clipBehavior: Clip.hardEdge,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: CachedNetworkImage(imageUrl: '${Address.homeHost}${model.image128}',
                        width: 40,height: 40,),
                    ),
                    SizedBox(width: 5,),
                    Text('${model.name}'),
                  ],
                ),
              ),
              Container(
                height: 0.5,
                color: AppColor.lineColor,
              )
            ],
          ),
        );
      },
      childCount: controller.dataArr.length,
    );
  }

}